const CryptoJS = require('crypto-js.min.js'); // 使用 crypto-js 库

const key = CryptoJS.enc.Hex.parse('345410943F60E9EDF54CBBD4C9484CFDF9DE704F0FA1F0B3DD9B492F263F9759'); // 16位密钥
const iv = CryptoJS.enc.Hex.parse('EF1202D9ABD84D5F509A7629469E73AE'); // 16位初始向量

function encryptData(data) {
  const encrypted = CryptoJS.AES.encrypt(data, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  const str = encrypted.toString();
  return str;
}

function decryptData(encryptedData) {
  const decrypted = CryptoJS.AES.decrypt(encryptedData, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  });
  return decrypted.toString(CryptoJS.enc.Utf8);
}

module.exports = {
  encryptData,
  decryptData
};